#pragma once
#include "user_singleton.hpp"
#include <Windows.h>

class CWaitForEvent : public Singleton<CWaitForEvent> {
	friend class Singleton<CWaitForEvent>;
	CWaitForEvent() = default;
public:
	void create();
	void start();
	void stop();
	void close();
	bool need_run(int times);
};

extern HANDLE STOP_EVENT;

#define WAIT_STOP_RETURN_VALUE(WAITTIME,RETURNVALUE)\
	if (WaitForSingleObject(STOP_EVENT,WAITTIME) == WAIT_OBJECT_0) {\
		return RETURNVALUE;\
	}


#define WAIT_STOP_RETURN(WAITTIME)\
	if (WaitForSingleObject(STOP_EVENT,WAITTIME) == WAIT_OBJECT_0) {\
		return;\
	}

#define WAIT_STOP_BREAK(WAITTIME)\
	if (WaitForSingleObject(STOP_EVENT, WAITTIME) == WAIT_OBJECT_0) {\
		break;\
	}

#define WAIT_SLEEP(WAITTIME)\
	if (WaitForSingleObject(STOP_EVENT,WAITTIME) == WAIT_OBJECT_0){}
